/**
 * Slot Machine, July 2012
 *
 * Owner: Rami Abou Ghanem
 * Owner: Sumbul Alvi
 *
 */

package Gui;

import java.awt.*; 
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.applet.*;
import java.awt.Frame;

public class Display extends Applet implements ActionListener {

	
	// all components which will be seen on the display
	Label lbl_title ;
	Button bttn_start ;
	TextField tf_bet, tf_numOfSlots ;
	CheckboxGroup cbg_lines ;
	Checkbox cb_1line, cb_3line, cb_5line ;
	TextArea ta_winnings, ta_credit ;
	Label lbl_winnings, lbl_credit, lbl_numberOfLines,lbl_bet, 
			lbl_numOfSlots ;
	
	int credit, bet, win, numberOfLines, numberOfSlots ;
	
	 public void init() 
     { 
		 
		 resize(400,500) ;
		 setLayout(null); 
		 //repaint(0) ;
		 
		 // init all components
		 //numberOfSlots = 3 ;
		 
		 // motherfuckin badass title
		 Font font_title = new Font("Helvetica", Font.BOLD, 25);
		 lbl_title = new Label("THIS BE DA SHIT. SLOTS!");
		 //lbl_title.setColor(Color.DARK_GRAY) ;
		 lbl_title.setFont(font_title) ;
		 
		 // the button that starts it all
		 bttn_start = new Button("GO") ;
		 bttn_start.setActionCommand("start");
		 bttn_start.addActionListener(this) ;
		 
		 // the radio button orgy, where only one can
		 // be true at a time in this specific group
		 // and the default is "1"
		 cbg_lines = new CheckboxGroup() ;
		 cb_1line = new Checkbox("1", cbg_lines,true) ;
		 cb_3line = new Checkbox ("3",cbg_lines,false) ;
		 cb_5line = new Checkbox ("5", cbg_lines,false) ;
		 
		 // TextArea (value, rows, cols, scrollbar_visibility)
		 // in this case we want no shitty scrollbars, so the 
		 // constant to use is SCROLLBAR_NONE which is 3
		 ta_winnings = new TextArea("0", 1,1,3) ;
		 ta_credit = new TextArea("10",2,2,3) ;
		 
		 // all the labels just for readability purposes
		 lbl_winnings = new Label("Win:") ;
		 lbl_credit = new Label("Credit:") ;
		 lbl_numberOfLines = new Label("Number of Lines:") ;
		 lbl_bet = new Label ("Bet:") ;
		 lbl_numOfSlots = new Label ("Number of Slots:") ;
		 
		 // place where playa enters their betting amount
		 tf_bet = new TextField("1") ;
		 
		 tf_numOfSlots = new TextField("3") ;
		 //tf_numOfSlots.setEditable(false) ;
		 
		 // bitch work. aka positioning of components on screen
		 bttn_start.setBounds(270, 350, 100,50) ;
		 cb_1line.setBounds (170,360,30,25) ;
		 cb_3line.setBounds(170,380,30,25) ;
		 cb_5line.setBounds(170,400,30,25) ;
		 ta_winnings.setBounds(50, 450,100,30) ;
		 ta_credit.setBounds(170,450,100,30) ;
		 tf_bet.setBounds(50,370,100,30) ;
		 tf_numOfSlots.setBounds(151,290,100,30) ;
		 lbl_winnings.setBounds(50,425,30,30) ;
		 lbl_credit.setBounds(170,425,50,30) ;
		 lbl_numberOfLines.setBounds(160, 340,100,30) ;
		 lbl_bet.setBounds(50,340,50,30) ;
		 lbl_numOfSlots.setBounds(151,270,100,30) ;
		 lbl_title.setBounds(40,6,400,40) ;
		 
		 // adding all components to applet
		 add(bttn_start) ;
		 add(cb_1line) ;
		 add(cb_3line) ;
		 add(cb_5line) ;
		 add(ta_winnings) ;
		 add(ta_credit) ;
		 add(tf_bet) ;
		 add(tf_numOfSlots) ;
		 add(lbl_winnings) ;
		 add(lbl_credit) ;
		 add(lbl_numberOfLines) ;
		 add(lbl_bet) ;
		 add(lbl_numOfSlots) ;
		 add(lbl_title) ;
		 
	}
	
	public void actionPerformed(ActionEvent e) {
		if ("start".equalsIgnoreCase(e.getActionCommand())) 
		{
			System.out.println("START EVERYTHING") ;
			// don't want the user to be clicking this a
			// million times at once or there will be a crash
			bttn_start.setEnabled(false) ;
			setFieldVals() ;
			repaint(1) ;
			
		}
		else if ("quit".equalsIgnoreCase(e.getActionCommand()))
		{
			// for a quit button which i'm too lazy to make right now
			System.out.println("YOU'LL BE BACK!!!") ;
			// destructors
			// destroy applet
			// clean up
		}
		else 
		{
			System.out.println("how the fuck did it get here?!") ;
		}
	}
	
	public void setFieldVals()
	{
		win = Integer.parseInt( ta_winnings.getText()) ;
		credit = Integer.parseInt(ta_credit.getText()) ;
		bet = Integer.parseInt(tf_bet.getText()) ;
		numberOfLines = Integer.parseInt((cbg_lines.getSelectedCheckbox()).getLabel()) ;
		numberOfSlots = Integer.parseInt(tf_numOfSlots.getText()) ;
		// might want to throw exception here for numberFormat thing
	}
	
	public void paint(Graphics g) {
		//the following also can be used for the title and is more flexible than
		// a label, however, need to find a way to eliminate 3 second delay  
		// at start up for this title
		/*g.setColor(Color.GREEN) ;
		g.setFont(new Font("Helvetica", Font.BOLD, 25)) ;
		g.drawString("MOTHERFUCKIN SLOTS",50,20) ;*/
		
		// when taking into account varying number of slots, the following
		// values will all be variables
		int x = 50, y = 50 , h = 70, w =100 ;
		DrawSlots d = new DrawSlots (numberOfSlots,x,y,h,w,g) ;
		d.drawToDisplay() ;
		
	}
}
